package io.github.ali.commons.lock.aop;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.PrioritizedParameterNameDiscoverer;
import org.springframework.core.annotation.Order;

import java.util.Map;

/**
 * @author bailey
 */
@Configuration
public class LockAspectConfiguration {
    @Bean
    @Order(2)
    public LockAspect aliLockAspect(ApplicationContext applicationContext) {
        Map<String, PrioritizedParameterNameDiscoverer> existed = applicationContext.getBeansOfType(PrioritizedParameterNameDiscoverer.class);
        return new LockAspect(existed.size() == 0 ? new DefaultParameterNameDiscoverer() : existed.get(0));
    }
}
